// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows.Media;
using TestClient.Domain;

namespace TestClient.ViewModel;
public partial class CommentTestViewModel : PageViewModelBase
{
    private const string lorem = """
        Lorem ipsum dolor sit amet, Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        """;


    [ObservableProperty]
    private string comment = "";
    [ObservableProperty]
    private string pointId = "";
    [ObservableProperty]
    private string fontName = "";
    [ObservableProperty]
    private double fontSize = 0.015;
    [ObservableProperty]
    private Color curColor = Color.FromRgb(0, 250, 0);

    public IAsyncRelayCommand SelectPointCommand { get; }
    public IAsyncRelayCommand AddCommentCommand { get; }
    public IAsyncRelayCommand RemoveCommentCommand { get; }

    public CommentTestViewModel(VFAdapterWrapper wrapper, ISnackNotifyService notifyService)
        : base(wrapper, notifyService)
    {
        SelectPointCommand = CreateAsyncRpcCommand(SelectPoint);
        AddCommentCommand = CreateAsyncRpcCommand(AddComment);
        RemoveCommentCommand = CreateAsyncRpcCommand(RemoveComment);
    }

    [RelayCommand]
    private void FillLorem()
    {
        Comment = lorem;
    }

    private async Task SelectPoint()
    {
        EnsureConnected();
        PointId = await ViewModelHelpers.SelectEnt(Wrapper, "Point");
    }
    private async Task AddComment()
    {
        EnsureConnected();
        await Task.Run(() =>
        {
            var loc = Wrapper.GetPointCoord(PointId);
            Wrapper.AddCommentOnPoint("-1", loc, Comment, CurColor, FontName, FontSize);
        });
    }
    private async Task RemoveComment()
    {
        EnsureConnected();
        await Task.Run(() =>
        {
            Wrapper.RemoveCommentOnPoint(PointId);
        });
    }
}
